﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.Xml;

namespace ShootSearch.Core
{
    [XmlRoot("Job")]
    public class JobConfig : AssemblyWithConfig, IXmlSerializable
    {
        public string Name { get; set; }
        public int IconIndex { get; set; }

        public JobConfig()
            : base()
        { }

        public JobConfig(ISpiderMan job)
            : base(job)
        {
            if (job != null)
            {
                Name = job.GetType().ToString();
            }
        }

        public JobConfig(Type jobType)
            : base(jobType)
        {
            if (jobType != null)
            {
                Name = jobType.ToString();
            }
        }



        #region IXmlSerializable Members

        System.Xml.Schema.XmlSchema IXmlSerializable.GetSchema()
        {
            return base.GetSchema();
        }

        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            reader.ReadToFollowing("Name");
            Name = reader.ReadString();

            reader.ReadToFollowing("IconIndex");
            IconIndex = reader.ReadElementContentAsInt();

            base.ReadXml(reader);
        }

        void IXmlSerializable.WriteXml(XmlWriter writer)
        {
            writer.WriteStartElement("Name");
            writer.WriteString(Name);
            writer.WriteEndElement();

            writer.WriteStartElement("IconIndex");
            writer.WriteValue(IconIndex);
            writer.WriteEndElement();
            base.WriteXml(writer);
        }

        #endregion
    }
}
